package com.reds.backend.service.impl.admin;

import com.reds.backend.pojo.Admin;
import com.reds.backend.utils.adminUtils.admin.StpAdminUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.reds.backend.service.admin.adminInfoService;
import com.reds.backend.mapper.adminMapper;

import java.util.HashMap;
import java.util.Map;

@Service
public class adminInfoServiceImpl implements  adminInfoService{
    @Autowired
    adminMapper adminMapper;
    @Override
    public Map<String,String> getAdminInfo() {
        int id  = StpAdminUtil.getLoginIdAsInt();
        Admin admin = adminMapper.selectById(id);
        Map<String,String> map = new HashMap<>();
        map.put("id",admin.getId()+"");
        map.put("name",admin.getName());
        map.put("email",admin.getEmail());
        map.put("role",admin.getRole());
        return map;
    }

    @Override
    public String loginCheck() {
        System.out.println(StpAdminUtil.getTokenValue()+"Service层的TOKEN");
        System.out.println(StpAdminUtil.getTokenValue());
        System.out.println(StpAdminUtil.getLoginIdAsInt());
        if(StpAdminUtil.isLogin()) return "success";
        else return "fail";
    }
}
